<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解 Spring MVC 核心：DispatcherServlet</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            position: relative;
            font-family: 'Consolas', 'Monaco', monospace;
        }
        
        .code-block::before {
            content: attr(data-lang);
            position: absolute;
            top: 8px;
            right: 12px;
            font-size: 12px;
            color: #666;
            text-transform: uppercase;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 12px;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
        }
        
        .timeline-item {
            position: relative;
            padding-left: 40px;
            margin-bottom: 30px;
        }
        
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 10px;
            top: 8px;
            width: 12px;
            height: 12px;
            background: #667eea;
            border-radius: 50%;
            box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
        }
        
        .timeline-item::after {
            content: '';
            position: absolute;
            left: 15px;
            top: 20px;
            bottom: -30px;
            width: 2px;
            background: #e5e7eb;
        }
        
        .timeline-item:last-child::after {
            display: none;
        }
        
        .highlight-text {
            background: linear-gradient(120deg, #ffd700 0%, #ffed4e 100%);
            padding: 2px 6px;
            border-radius: 4px;
            font-weight: 500;
        }
        
        @keyframes float {
            0% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
            100% { transform: translateY(0px); }
        }
        
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6 relative">
        <div class="max-w-6xl mx-auto relative z-10">
            <div class="text-center">
                <div class="floating-icon inline-block mb-6">
                    <i class="fas fa-cogs text-6xl"></i>
                </div>
                <h1 class="text-5xl md:text-6xl font-bold mb-6" style="font-family: 'Noto Serif SC', serif;">
                    深入理解 DispatcherServlet
                </h1>
                <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto">
                    探索 Spring MVC 的核心引擎，掌握请求处理的艺术
                </p>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <div class="flex items-start space-x-4">
                <div class="feature-icon">
                    <i class="fas fa-info-circle"></i>
                </div>
                <div class="flex-1">
                    <h2 class="text-2xl font-bold mb-4">什么是 DispatcherServlet？</h2>
                    <p class="text-gray-700 leading-relaxed text-lg">
                        <code class="highlight-text">DispatcherServlet</code> 是 Spring MVC 的核心组件，负责处理所有的请求，并将请求分发给适当的处理器。它是一个前端控制器（Front Controller）模式的实现，负责协调 Spring MVC 的各个组件。
                    </p>
                </div>
            </div>
        </div>

        <!-- Architecture Diagram -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="text-2xl font-bold mb-6 section-title">架构概览</h2>
            <div class="mermaid">
                graph TB
                    A[客户端请求] --> B[DispatcherServlet]
                    B --> C[HandlerMapping]
                    C --> D[Controller]
                    D --> E[Model]
                    D --> F[ViewResolver]
                    F --> G[View]
                    G --> H[响应客户端]
                    
                    style A fill:#ffd700,stroke:#333,stroke-width:2px
                    style B fill:#667eea,stroke:#333,stroke-width:3px,color:#fff
                    style H fill:#90EE90,stroke:#333,stroke-width:2px
            </div>
        </div>

        <!-- Initialization Section -->
        <div class="grid md:grid-cols-2 gap-8 mb-12">
            <div class="content-card rounded-2xl p-8">
                <div class="feature-icon">
                    <i class="fas fa-rocket"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 section-title">初始化过程</h3>
                
                <div class="space-y-4">
                    <div class="timeline-item">
                        <h4 class="font-semibold text-lg mb-2">Servlet 配置</h4>
                        <p class="text-gray-700">
                            DispatcherServlet 通常在 <code class="text-purple-600 bg-purple-50 px-2 py-1 rounded">web.xml</code> 配置文件中进行注册，或通过 Java 配置类注册。
                        </p>
                    </div>
                    
                    <div class="timeline-item">
                        <h4 class="font-semibold text-lg mb-2">初始化参数</h4>
                        <p class="text-gray-700">
                            可以通过 <code class="text-purple-600 bg-purple-50 px-2 py-1 rounded">&lt;init-param&gt;</code> 配置初始化参数，如指定 Spring 配置文件路径。
                        </p>
                    </div>
                    
                    <div class="timeline-item">
                        <h4 class="font-semibold text-lg mb-2">Spring 容器</h4>
                        <p class="text-gray-700">
                            创建 Spring 应用上下文（ApplicationContext），管理所有 Spring MVC 的 Bean。
                        </p>
                    </div>
                </div>
            </div>

            <div class="content-card rounded-2xl p-8">
                <div class="feature-icon">
                    <i class="fas fa-cube"></i>
                </div>
                <h3 class="text-2xl font-bold mb-4 section-title">初始化 Bean</h3>
                
                <div class="space-y-4">
                    <div class="bg-gray-50 rounded-lg p-4">
                        <h4 class="font-semibold mb-2 flex items-center">
                            <i class="fas fa-layer-group mr-2 text-purple-600"></i>
                            Bean 加载
                        </h4>
                        <p class="text-gray-700">
                            加载并初始化 Spring MVC 相关的 Bean，包括处理器映射器、适配器、视图解析器等。
                        </p>
                    </div>
                    
                    <div class="bg-gray-50 rounded-lg p-4">
                        <h4 class="font-semibold mb-2 flex items-center">
                            <i class="fas fa-cog mr-2 text-purple-600"></i>
                            配置处理器
                        </h4>
                        <p class="text-gray-700">
                            查找并注册所有的 HandlerMapping、HandlerAdapter 和 ViewResolver。
                        </p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Configuration Examples -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="text-2xl font-bold mb-6 section-title">配置示例</h2>
            
            <div class="mb-8">
                <h3 class="text-xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-file-code mr-2 text-purple-600"></i>
                    XML 配置方式
                </h3>
                <div class="code-block" data-lang="xml">
                    <pre>&lt;servlet&gt;
    &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
&lt;/servlet&gt;

&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;</pre>
                </div>
            </div>
            
            <div>
                <h3 class="text-xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-coffee mr-2 text-purple-600"></i>
                    Java 配置方式
                </h3>
                <div class="code-block" data-lang="java">
                    <pre>@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
    
    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
    
    // 配置其他 Bean
}</pre>
                </div>
            </div>
        </div>

        <!-- Lifecycle Section -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="text-2xl font-bold mb-6 section-title">生命周期管理</h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-gradient-to-br from-green-50 to-green-100 rounded-xl p-6 border border-green-200">
                    <div class="text-green-600 text-3xl mb-4">
                        <i class="fas fa-play-circle"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">初始化阶段</h3>
                    <p class="text-gray-700">
                        应用启动时调用 <code class="text-green-700 font-mono">init()</code> 方法，